package com.cby.android.sample.utils

import android.content.Context
import android.location.Address
import android.location.Geocoder
import android.location.Location
import android.util.Log
import java.util.*

/**
 * @description: LocationUtils
 * @author: ChenBaoYang
 * @createDate: 2022/5/6 5:18 下午
 */
object LocationUtils {

    fun getAddress(context: Context, location : Location?) :List<Address>  {
        var result = mutableListOf<Address>()
        try {
            if (location != null) {
                val gc = Geocoder(context, Locale.getDefault());
                result = gc.getFromLocation(location.latitude,
                    location.longitude, 1)
            }
            if(result.size > 0) {
                Log.i("chenby",result[0].toString())
            }

        } catch (e: Exception) {
            e.printStackTrace()
        }
        return result
    }
}